package com.dtgrid.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.dtgrid.jfinal.Convert;
import com.jfinal.plugin.activerecord.Record;

import net.sf.json.JSONObject;

public class Pager {

	/**
	 * 是否出错
	 */
	private boolean isSuccess;

	/**
	 * 每页显示条数
	 */
	private int pageSize;

	/**
	 * 开始记录数
	 */
	private int startRecord;

	/**
	 * 当前页数
	 */
	private int nowPage;

	/**
	 * 记录总数
	 */
	private int recordCount;

	/**
	 * 总页数
	 */
	private int pageCount;

	/**
	 * 参数列表
	 */
	private Map<String, Object> parameters;

	/**
	 * 快速查询参数列表
	 */
	private Map<String, Object> fastQueryParameters;

	/**
	 * 高级查询列表
	 */
	private List<Condition> advanceQueryConditions;

	/**
	 * 高级排序列表
	 */
	private List<Sort> advanceQuerySorts;

	/**
	 * 显示数据集
	 */
	private List<Map<String, Object>> exhibitDatas;

	/**
	 * 是否导出：1-是，0-否
	 */
	private boolean isExport;

	/**
	 * 导出类型，支持excel、pdf、txt、cvs
	 */
	private String exportType;

	/**
	 * 导出文件名
	 */
	private String exportFileName;

	/**
	 * 导出列
	 */
	private List<Column> exportColumns;

	/**
	 * 全部数据导出
	 */
	private boolean exportAllData;

	/**
	 * 导出数据是否已被加工
	 */
	private boolean exportDataIsProcessed;

	/**
	 * 导出数据
	 */
	private List<Map<String, Object>> exportDatas;

	public boolean getIsSuccess() {
		return isSuccess;
	}

	public void setIsSuccess(boolean isSuccess) {
		this.isSuccess = isSuccess;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getStartRecord() {
		return startRecord;
	}

	public void setStartRecord(int startRecord) {
		this.startRecord = startRecord;
	}

	public int getNowPage() {
		return nowPage;
	}

	public void setNowPage(int nowPage) {
		this.nowPage = nowPage;
	}

	public int getRecordCount() {
		return recordCount;
	}

	public void setRecordCount(int recordCount) {
		this.recordCount = recordCount;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public Map<String, Object> getParameters() {
		return parameters;
	}

	public void setParameters(Map<String, Object> parameters) {
		this.parameters = parameters;
	}

	public Map<String, Object> getFastQueryParameters() {
		return fastQueryParameters;
	}

	public void setFastQueryParameters(Map<String, Object> fastQueryParameters) {
		this.fastQueryParameters = fastQueryParameters;
	}

	public List<Condition> getAdvanceQueryConditions() {
		return advanceQueryConditions;
	}

	public void setAdvanceQueryConditions(List<Condition> advanceQueryConditions) {
		this.advanceQueryConditions = advanceQueryConditions;
	}

	public List<Sort> getAdvanceQuerySorts() {
		return advanceQuerySorts;
	}

	public void setAdvanceQuerySorts(List<Sort> advanceQuerySorts) {
		this.advanceQuerySorts = advanceQuerySorts;
	}

	public List<Map<String, Object>> getExhibitDatas() {
		return exhibitDatas;
	}

	public void setExhibitDatas(List<Map<String, Object>> exhibitDatas) {
		this.exhibitDatas = exhibitDatas;
	}
	
	private List<Map<String, Object>> ExhibitDatasFromRecord;
	public List<Map<String, Object>> getExhibitDatasFromRecord() {
		return ExhibitDatasFromRecord;
	}
	public void setExhibitDatasFromRecord(List<Record> exportRecord) {
		List<Map<String, Object>> exhibitDatas = Convert.listRecord2ListObject(exportRecord);
		this.exhibitDatas = exhibitDatas;
	}
	
	private List<Map<String, Object>> ExhibitDatasFromJsonArray;
	public List<Map<String, Object>> getExhibitDatasFromJsonArray() {
		return ExhibitDatasFromJsonArray;
	}
	public void setExhibitDatasFromJsonArray(net.sf.json.JSONArray ja) {
		List<Map<String, Object>> exhibitDatas = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < ja.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>();

			JSONObject jb = JSONObject.fromObject(ja.get(i).toString());
			Iterator<?> it = jb.keys();
			// 遍历jsonObject数据，添加到Map对象
			while (it.hasNext()) {
				String key = String.valueOf(it.next());
				if (jb.get(key) instanceof String) {
					String value = (String) jb.get(key);
					map.put(key, value);
				}else if (jb.get(key) instanceof Integer) {
					Integer value = (Integer) jb.get(key);
					map.put(key, value);
				}else if (jb.get(key) instanceof Double) {
					Double value = (Double) jb.get(key);
					map.put(key, value);
				}else if (jb.get(key) instanceof Long) {
					Long value = (Long) jb.get(key);
					map.put(key, value);
				}
				else if (jb.get(key) instanceof Boolean) {
					Boolean value = (Boolean) jb.get(key);
					map.put(key, value);
				}else if (jb.get(key) instanceof JSONObject) {
					JSONObject value = (JSONObject) jb.get(key);
					map.put(key, value);
				}						
				else{
					//其他类型待添加
					System.out.println("error:" + jb.get(key) + ":==" + jb.get(key).getClass().getName());
				}
			}
			exhibitDatas.add(map);
		}
		this.exhibitDatas = exhibitDatas;
	}

	public boolean getIsExport() {
		return isExport;
	}

	public void setIsExport(boolean isExport) {
		this.isExport = isExport;
	}

	public String getExportType() {
		return exportType;
	}

	public void setExportType(String exportType) {
		this.exportType = exportType;
	}

	public String getExportFileName() {
		return exportFileName;
	}

	public void setExportFileName(String exportFileName) {
		this.exportFileName = exportFileName;
	}

	public List<Column> getExportColumns() {
		return exportColumns;
	}

	public void setExportColumns(List<Column> exportColumns) {
		this.exportColumns = exportColumns;
	}

	public boolean getExportAllData() {
		return exportAllData;
	}

	public void setExportAllData(boolean exportAllData) {
		this.exportAllData = exportAllData;
	}

	public boolean getExportDataIsProcessed() {
		return exportDataIsProcessed;
	}

	public void setExportDataIsProcessed(boolean exportDataIsProcessed) {
		this.exportDataIsProcessed = exportDataIsProcessed;
	}

	public List<Map<String, Object>> getExportDatas() {
		return exportDatas;
	}

	public void setExportDatas(List<Map<String, Object>> exportDatas) {
		this.exportDatas = exportDatas;
	}
	
	private List<Map<String, Object>> ExportDatasFromRecord;	
	public List<Map<String, Object>> getExportDatasFromRecord() {
		return ExportDatasFromRecord;
	}


	public void setExportDatasFromRecord(List<Record> exportRecord) {
		List<Map<String, Object>> exportDatas = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < exportRecord.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			Record rc = exportRecord.get(i);
			String[] colNames =  rc.getColumnNames();
			for(int j = 0; j < colNames.length; j++){
				String key = String.valueOf(colNames[j]);
				if (rc.get(key) instanceof String) {
					String value = (String) rc.get(key);
					map.put(key, value);
				}
				if (rc.get(key) instanceof Integer) {
					Integer value = (Integer) rc.get(key);
					map.put(key, value);
				}else if (rc.get(key) instanceof Double) {
					Double value = (Double) rc.get(key);
					map.put(key, value);
				}else if (rc.get(key) instanceof Long) {
					Long value = (Long) rc.get(key);
					map.put(key, value);
				}
				else if (rc.get(key) instanceof Boolean) {
					Boolean value = (Boolean) rc.get(key);
					map.put(key, value);
				}				
				else{
					//其他类型待添加
					System.out.println("setExhibitDatasFromJsonArray error");
				}
			}
			exportDatas.add(map);
		}
		this.exportDatas = exportDatas;
	}
	
	private List<Map<String, Object>> ExportDatasFromJsonArray;
	
	public List<Map<String, Object>> getExportDatasFromJsonArray() {
		return ExportDatasFromJsonArray;
	}

	public void setExportDatasFromJsonArray(net.sf.json.JSONArray ja) {
		List<Map<String, Object>> exportDatas = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < ja.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>();

			JSONObject jb = JSONObject.fromObject(ja.get(i).toString());
			Iterator<?> it = jb.keys();
			// 遍历jsonObject数据，添加到Map对象
			while (it.hasNext()) {
				String key = String.valueOf(it.next());
				if (jb.get(key) instanceof String) {
					String value = (String) jb.get(key);
					map.put(key, value);
				}else if (jb.get(key) instanceof Integer) {
					Integer value = (Integer) jb.get(key);
					map.put(key, value);
				}else if (jb.get(key) instanceof Double) {
					Double value = (Double) jb.get(key);
					map.put(key, value);
				}else if (jb.get(key) instanceof Long) {
					Long value = (Long) jb.get(key);
					map.put(key, value);
				}
				else if (jb.get(key) instanceof Boolean) {
					Boolean value = (Boolean) jb.get(key);
					map.put(key, value);
				}				
				else{
					//其他类型待添加
					System.out.println("setExhibitDatasFromJsonArray error");
				}
			}
			exportDatas.add(map);
		}
		this.exportDatas = exportDatas;
	}
}
